//
//  HCNavigationController.swift
//  Hweibome
//
//  Created by 何川 on 15/12/6.
//  Copyright © 2015年 hechuan. All rights reserved.
//

import UIKit

class HCNavigationController: UINavigationController ,UIGestureRecognizerDelegate{

    override func viewDidLoad() {
        super.viewDidLoad()
        self.interactivePopGestureRecognizer?.delegate = self
        // Do any additional setup after loading the view.
    }
    
    override func pushViewController(viewController: UIViewController, animated: Bool) {
        
        if childViewControllers.count != 0
        {
        var title :String = "返回"
            if childViewControllers.count == 1
            {
                title = childViewControllers.first?.title ?? title
            }
            viewController.navigationItem.leftBarButtonItem = UIBarButtonItem(imgName: "navigationbar_back_withtext", title: title, target: self, action: "back")
           
            //ios7 出来的bug，来回push pop 就会出现黑条
            //解决方法 设置背景颜色8：40分讲的12月8日
            viewController.hidesBottomBarWhenPushed = true
        }
        super.pushViewController(viewController, animated: animated)
    }

    @objc private func back()
    {
        popViewControllerAnimated(true)
    }
    
    func gestureRecognizerShouldBegin(gestureRecognizer: UIGestureRecognizer) -> Bool {
        printLog("gestureRecognizerShouldBegin")
        return childViewControllers.count != 1
    }


}
